package com.minimalist.basic.controller.basic;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.minimalist.basic.service.OperatorLogService;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.basic.vo.operatorlog.OperatorLogQueryVO;
import com.minimalist.common.entity.basic.vo.operatorlog.OperatorLogVO;
import com.minimalist.common.response.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RestController
@Tag(name = "操作日志管理")
@RequestMapping("/basic/operatorlog")
class OperatorLogController{
    
    private final OperatorLogService operatorLogService;
    
    public OperatorLogController(OperatorLogService operatorLogService) {
        this.operatorLogService = operatorLogService;
    }

    @GetMapping("/getPageOperatorLogList")
    @SaCheckPermission("basic:operatorlog:get")
    @Operation(summary = "查询参数配置列表(分页)")
    public R<PageResp<OperatorLogVO>> getPageConfigList(
            OperatorLogQueryVO queryVO){
        return R.ok(operatorLogService.getPageOperatorList(queryVO));
    }

    @DeleteMapping("/deleteOperatorLogByOperatorLogId")
    @SaCheckPermission("basic:operatorlog:delete")
    @Operation(summary = "删除操作日志 -> 根据操作日志ID删除")
    public R<?> deleteOperatorLogByOperatorLogId(
            @RequestParam("operatorLogId")
            @NotNull(message = "操作日志ID不能为空")
            @Parameter(name = "operatorLogId", required = true, description = "操作日志ID")
            Long operatorLogId){
        operatorLogService.deleteOperatorLogByOperatorLogId(operatorLogId);
        return R.ok();
    }

    @PostMapping("/deleteOperatorLogByOperatorLogIds")
    @SaCheckPermission("basic:operatorlog:delete")
    @Operation(summary = "批量删除操作日志 -> 根据操作日志iD集合删除")
    public R<?> deleteOperatorLogByOperatorLogId(
            @RequestBody
            @NotNull(message = "操作日志ID集合不能为空")
            @Parameter(name = "operatorLogIds", required = true, description = "操作日志ID集合")
            List<Long> operatorLogIds){
        operatorLogService.deleteOperatorLogByOperatorLogIds(operatorLogIds);
        return R.ok();
    }

    @GetMapping("/getOperatorLogByOperatorLogId/{operatorLogId}")
    @SaCheckPermission("basic:operatorlog:get")
    @Operation(summary = "根据操作日志ID查询参数")
    public R<OperatorLogVO> getOperatorLogByOperatorLogId(
            @PathVariable(value = "operatorLogId")
            @NotNull(message = "操作日志ID不能为空")
            @Parameter(name = "operatorLogId", description = "操作日志ID", required = true)
            Long operatorLogId){
        return R.ok(operatorLogService.getOperatorLogByOperatorLogId(operatorLogId));
    }
}